<template>
<view>
    <view v-if="formObj.value == '' || formObj.value.length == 0">

        <u-input  type="select" :select-open="pickerShow" v-model="city" :placeholder="addressObj.placeholder" @click="chooseAddress"></u-input>
		<u-picker mode="region" v-model="pickerShow" @confirm="regionConfirms"></u-picker>
        <textarea  placeholder="填写详细地址" @blur="bindTextAreaBlur"  v-model="detail" auto-height/>
  
    </view>
    <view v-else>
        {{formObj.value}}
    </view>
</view>
</template>


<script>

export default {

    props: {
         formObj: {
            type: Object,
            
        }
    },

    data () {
        return {
            city: '',
            pickerShow: false,
            addressObj: {},
            detail:''
            


        }
    },
    mounted() {
        
        this.addressObj = this.formObj
        console.log(this.formObj.value)

    },
    
    methods: {

        chooseAddress() {
            this.city = ''
            this.pickerShow = true

        },

        regionConfirms(e) {

            this.city  = e.province.label + '-' + e.city.label + '-' + e.area.label;
            var realaddress =  e.province.label  + e.city.label  + e.area.label;
            var obj = {
                key: this.addressObj.name,
                value: realaddress
            }
            // this.$emit('childFn',obj)
            if(this.detail == ''){
                uni.showToast({
                    title:'请填入详细地址',
                    icon: 'none'
                })

                return
            }else{

                obj.value = realaddress + this.detail
                this.$emit('childFn',obj)

            }


        },
        bindTextAreaBlur(e) {

            if(this.city == ''){
                uni.showToast({
                    title: '请选择省市区',
                    icon: 'none'
                })

                return  false
            }

            this.detail = e.target.value
           
            var obj = {
                key: this.addressObj.name,
                value: this.city.split('-').join('')+e.target.value
            }
            this.$emit('childFn',obj)
		},
    }
    
}
</script>


<style lang="less" scoped>

</style>